#!/usr/bin/python
# Splits a fastq file into multiple.
import sys
import os

# Parameters.
input_unk = sys.argv[1]

# check if dir.
files = []
if os.path.isdir(input_unk):
	for f in os.listdir(input_unk):
		files.append("%s/%s" % (input_unk, f))
else:
	files.append(input_unk)
	
# Read statistics.
for input_file in files:
	# setup.
	total = 0
	cnt = 0
	first = True
	fin = open(input_file, "rb")
	for line in fin:
		# check if we start new entry.
		if line[0] == "@":
			# tally.
			if first != True:
				cnt += 1
				total += size
			else:
				first = False
				
			# clear.
			skip = False
			size = 0
			continue
		
		elif line[0] == "+":
			skip = True
		
		# note size.
		if skip == False:
			size += len(line) - 1

	# Tally last.
	cnt += 1
	total += size
	fin.close()
	
	# Print summary.
	print "%s\t%i\t%i\t%f" % (input_file, cnt, total, float(total)/float(cnt))


